<?php

namespace App\Http\Controllers\Api\Miniprogram;

use App\Http\Controllers\Controller;
use App\Models\Cms\QuestionAnswer;
use App\Models\Cms\QuestionCategory;

class QuestionController extends Controller
{
    public function categories()
    {
        return $this->successJson(QuestionCategory::with(['icon'])->where('status', 1)->orderBy('order')->get());
    }

    public function getList()
    {
        $categoryId = request('id');
        return $this->successJson([
            'category' => QuestionCategory::with(['icon'])->where('id', $categoryId)->first(),
            'list' => QuestionAnswer::with(['questionCategory'])->where('question_category_id', $categoryId)->where('status', 1)->orderBy('order')->get()
        ]);
    }

    public function getDetail()
    {
        $id = request('id');
        return $this->successJson(QuestionAnswer::with(['questionCategory'])->where('status', 1)->find($id));
    }
}
